﻿
// Copyright © 2009 Mehdi Golchin. All rights reserved.

namespace TinyMceWrapper
{

    #region [ Imports ]

    using System;
    using System.ComponentModel;

    #endregion

    public static class Utilities
    {

        #region [ Public Static Methods ]

        public static void NotNull<TClass>(TClass value, string parameterName) where TClass : class
        {
            if (value == null)
                throw new ArgumentNullException(parameterName);
        }

        public static void NotNull<TStructure>(TStructure value, TStructure initialValue, string parameterName) where TStructure : struct
        {
            if (value.Equals(initialValue))
                throw new ArgumentNullException(parameterName);
        }

        public static void NotNullOrEmpty(string value, string parameterName)
        {
            NotNull(value, parameterName);

            if (value.Length == 0)
                throw new ArgumentNullException(parameterName);
        }

        public static bool IsNumeric(string value)
        {
            double res;
            return IsNumeric(value, out res);
        }

        public static bool IsNumeric(string value, out double result)
        {
            return double.TryParse(value, out result);
        }

        public static bool IsBool(string value)
        {
            bool res;
            return IsBool(value, out res);
        }

        public static bool IsBool(string value, out bool result)
        {
            return bool.TryParse(value, out result);
        }

        public static void ThrowException<TException>(bool clause, params object[] args) where TException : Exception
        {
            if (clause) throw (Exception)Activator.CreateInstance(typeof(TException), args);
        }

        #endregion

    }

}
